new Vue({
  el: "#app",
  mixins: [Query], //组件配置文件，路径/utils/components.js
  data() {
    return {
      form: {
        //查询筛选
        value: "",
        PageNumber: 1, //页码
        RowAmount: 20,
        Condition: utf8ToBase64("%%"),
      },
      TranCodes:[],
      
    };
    
  },
  mounted() {
    /**
     * 组件配置文件中自动执行方法
     * 1.this.getColumn(); //查询表头数据
     * 2.this.getList(this.form); //查询表格数据
     * 3.this.getTreeData();//查询树
     */
  },
  methods: {
    handleSerach() {
      //筛选
      this.form.Condition = utf8ToBase64(`%${this.form.value}%`);
      this.getList(this.form);
    },

    // 申请方法

    // 申请方法 - 修复版本
    async handleApply(row) {
      try {
         const [TranCode] = await Promise.all([
          httpRequest({
            url: "/generalBusiness/generalQueryByTableNameWithOriginal",
            data: {
              Data: "MoTask_Finished",
              Condition: `MoTask_Finished_SerialNumber='${row.MoTask_Finished_SerialNumber}' AND Row_Status='0'`,
            },
          }),
         
        ]);
       console.log(row)

        // 1. 设置申请状态
        
        TranCode[0].TranCodeApplyStatus = 1;
        this.TranCodes = TranCode;
        // 2. 手动构建提交数据结构（替代 generateStructure()）
        const submitData = {
          Modify: {
                MoTask_Finished: [...this.TranCodes],
          },
        };

        console.log("提交的数据结构:", submitData);

        // 3. 调用API提交数据
        const res = await httpRequest({
          contentType: "JSON",
          url: "/generalBusiness/generalSaveByRequestBody",
          data: JSON.stringify({
            Data: submitData,
          }),
        });

        // 4. 处理响应结果
        if (res.Status == "success") {
          this.$message.success("申请成功");
          this.getList(this.form); // 刷新列表，显示最新状态
        } else {
          this.$message.error("申请失败，请重试！");
        }
      } catch (error) {
        console.error("申请操作失败:", error);
        this.$message.error("系统错误，请联系开发者!");
      }
    },
    handleEdit(row) {//点击查看
            try {
                const { primaryKey } = $('#table').data('options');
                window.location.href = "./look.html?action=Modify&nodeKey=" + row[primaryKey];
            } catch (error) {
                console.error(error);
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            }
        },
  },
});
